package com.briup.ch08;

import java.util.*;

/**
 * @Author briup-adam
 * @Date 2023/10/16 上午11:24
 * @Description 斗地主
 **/

public class PlayCard {
    private static List<Card> cards = new ArrayList();
    private static String[] kinds = {"♥", "♠", "♣", "♦"};
    private static String[] numbers = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K","A", "2"};
    private static Map<String, List<Card>> map = new HashMap();

    //生成扑克牌
    public static void makeCards() {
        for (String kind : kinds) {
            int i=1;
            for (String number : numbers) {
//                创建扑克牌
                Card card = new Card(kind, number, i++);
                cards.add(card);
            }
        }
        Collections.addAll(cards, new Card("大","🤡",15),new Card("小","🤡",14));
    }

    //洗牌
    public static void shuffle() {
        Collections.shuffle(cards);
    }

    //发牌  需要三个玩家
    public static void deal(String name1, String name2, String name3) {
        ArrayList<Card> cards1 = new ArrayList<>();
        ArrayList<Card> cards2 = new ArrayList<>();
        ArrayList<Card> cards3 = new ArrayList<>();
        for (int i = 0; i < cards.size() - 3; i++) {
            switch (i % 3) {
                case 0:
                    cards1.add(cards.get(i));
                    break;
                case 1:
                    cards2.add(cards.get(i));
                    break;
                case 2:
                    cards3.add(cards.get(i));
                    break;
            }
        }
        map.put(name1, cards1);
        map.put(name2, cards2);
        map.put(name3, cards3);
        //底牌
        map.put("bottomCards",cards.subList(cards.size()-3,cards.size()));
    }

    public static void cat() {
        Set<Map.Entry<String, List<Card>>> entrySet = map.entrySet();
        for (Map.Entry<String, List<Card>> entry : entrySet) {
            Collections.sort(entry.getValue());
            System.out.println(entry.getKey()+":"+entry.getValue());
        }

    }

    public static void main(String[] args) {
        makeCards();
        shuffle();
        deal("赵健","刘成智","李建豪");
        cat();
    }
}
class  Card  implements  Comparable<Card>{
    private  String  kind;
    private  String number;
    //权重
    private  int val;

    @Override
    public String toString() {
        return  kind  + number ;
    }

    public Card() {
    }

    public Card(String kind, String number, int val) {
        this.kind = kind;
        this.number = number;
        this.val = val;
    }

    public String getKind() {
        return kind;
    }

    public String getNumber() {
        return number;
    }

    public int getVal() {
        return val;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public void setVal(int val) {
        this.val = val;
    }

    @Override
    public int compareTo(Card o) {
        return -(this.val-o.val);
    }
}